import React from 'react';
import {Button, Icon, Tooltip} from 'antd';
import {WeaLocaleProvider, WeaDialog} from 'ecCom';
const getLabel = WeaLocaleProvider.getLabel;

class Confirm extends React.Component {
    state = {visible: false, templateType: '', data: {}};

    constructor(props) {
        super(props);
        this.getButtons = this.getButtons.bind(this);
        this.onCancel = this.onCancel.bind(this);
    }

    render() {
        const {visible, templateType, data} = this.state;
        const {detailinfo = {}} = data;
        const {successList = [], failList = []} = detailinfo;

        return (
            <WeaDialog
                visible={visible}
                title={getLabel(386786, '信息确认')}
                icon="icon-coms-currency"
                iconBgcolor='#217346'
                style={{width: 500, height: 300}}
                zIndex={100}
                hasScroll={true}
                buttons={this.getButtons()}
                onCancel={this.onCancel}
            >
                <div className="wea-non-standard-confirm">
                    {
                        successList && successList.length ? (
                                <div className="wea-non-standard-confirm-success">
                                    <div className="wea-non-standard-confirm-title">
                                        <Icon type="check-circle" style={{color: '#1a9437', fontSize: '14px'}}/>
                                        <span style={{marginLeft: '10px'}}>{templateType == '0' ? getLabel(0, '以下非标功能停用成功') : getLabel(0, '以下非标功能启用成功')}</span>
                                    </div>
                                    <div className="wea-non-standard-confirm-list">
                                        <ul>
                                            {
                                                successList.map((item, index) => {
                                                    return (
                                                        <li key={index}>
                                                            <span className="wea-non-standard-confirm-id">{item.id}</span>
                                                            <span className="wea-non-standard-confirm-name">{item.name}</span>
                                                        </li>
                                                    );
                                                })
                                            }
                                        </ul>
                                    </div>
                                </div>
                            ) : ''
                    }
                    {
                        failList && failList.length ? (
                                <div className="wea-non-standard-confirm-failure">
                                    <div className="wea-non-standard-confirm-title">
                                        <Icon type="exclamation-circle" style={{color: '#db525a', fontSize: '14px'}}/>
                                        <span style={{marginLeft: '10px'}}>{templateType == '0' ? getLabel(0, '以下非标功能停用失败') : getLabel(0, '以下非标功能启用失败')}</span>
                                    </div>
                                    <div className="wea-non-standard-confirm-list">
                                        <ul>
                                            {
                                                failList.map((item, index) => {
                                                    return (
                                                        <li key={index}>
                                                            <span className="wea-non-standard-confirm-id">{item.id}</span>
                                                            <span className="wea-non-standard-confirm-name">{item.name}</span>
                                                            <Tooltip overlayClassName="wea-non-standard-confirm-tooltip" placement="bottom" title={item.msg}>
                                                                <span className="wea-non-standard-confirm-msg">{getLabel(27041, '失败原因')}</span>
                                                            </Tooltip>
                                                        </li>
                                                    );
                                                })
                                            }
                                        </ul>
                                    </div>
                                </div>
                            ) : ''
                    }
                </div>
            </WeaDialog>
        );
    }

    getButtons() {
        let buttons = [];
        buttons.push(<Button type="primary" onClick={this.onCancel}>{getLabel(83446, '确定')}</Button>);
        return buttons;
    }

    onCancel() {
        this.setState({visible: false});
    }

    onShow(templateType, data) {
        this.setState({visible: true, templateType, data});
    }
}

export default Confirm;
